package com.agsmobi.digitapp;

import java.util.ArrayList;

import android.os.Bundle;
import android.view.MotionEvent;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

public class StarPartcleEffectActivity extends BaseActivity {
	
	protected int duration;
	protected int numberOfStars;
	protected int sound;
	
	private RelativeLayout reMain;
	private ArrayList<ImageView> stars;
	private ImageView imgTest;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_starpartcleeffect);
		loadControl();
		loadData();
	}

	@Override
	protected void loadControl() {
		// TODO Auto-generated method stub
		super.loadControl();
		reMain = (RelativeLayout)findViewById(R.id.reMain);
		imgTest = (ImageView)findViewById(R.id.imgTest);
	}

	@Override
	protected void loadData() {
		// TODO Auto-generated method stub
		super.loadData();
		duration = 3000;
		numberOfStars = 8;
		Animation animation = new TranslateAnimation(0,0, -150,-200);
		animation.setDuration(duration);
		animation.setFillAfter(true);
		imgTest.startAnimation(animation);
	}
	/*
	 * 
	 */
	private void start(int x,int y){
		reMain.removeAllViews();
		LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
		params.setMargins(x, y, 0,0);
		stars = new ArrayList<ImageView>();
		
		for(int i = 0;i<numberOfStars;i++){
			ImageView temp = new ImageView(this);
			temp.setId(i*10);
			temp.setBackgroundResource(R.drawable.star);
			temp.setLayoutParams(params);
			stars.add(temp);
			reMain.addView(temp);
		}
		
		Animation animation = new TranslateAnimation(0,0, -150,-200);
		animation.setDuration(duration);
		animation.setFillAfter(true);
		
		Animation animation1 = new TranslateAnimation(40,5, -150,-50);
		animation1.setDuration(duration);
		animation1.setFillAfter(true);
		
		Animation animation2 = new TranslateAnimation(10,20, -30,-10);
		animation2.setDuration(duration);
		animation2.setFillAfter(true);
		
		Animation animation3 = new TranslateAnimation(100,10, -70,-70);
		animation3.setDuration(duration);
		animation3.setFillAfter(true);
		
		
		
		for(int i = 0;i<numberOfStars;i++){
			if(i==0){
				stars.get(i).startAnimation(animation);
			}
			else if(i==1){
				stars.get(i).startAnimation(animation1);
			}
			else if(i==2){
				stars.get(i).startAnimation(animation2);
			}
			else if(i==3){
				stars.get(i).startAnimation(animation3);
			}
		}
		
		
		
		
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		int x = (int)event.getX();
	    int y = (int)event.getY();
	    start(x,y);
	    return super.onTouchEvent(event);
	}

}
